home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / tool / fxcdl / src / tspath.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  1.9 KB  |  96 lines

  1. /*********************************************************************
  2.     for LSI C-86 v3.30 試食版
  3. *********************************************************************/
  4.  
  5. #include "tspath.h"
  6. #include "tsmacro.h"
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. // パス名を構成要素に分解する
  13. //   動作はMetaWate High C Compiler v1.7 の _splitpath()関数に
  14. //   可能な限り合わせてあります。
  15. extern void        splitPath(
  16.         char *path,                // 変換するパス
  17.         char *drive,            // ドライブ名
  18.         char *dir,                // ディレクトリ名
  19.         char *fname,            // ファイル名
  20.         char *ext                // 拡張子
  21. )
  22. {
  23.     int        i, n;
  24.     char    c;
  25.     int        colon, yen, fnend, period, tail;
  26.     colon = yen = period = -1;
  27.     drive[0] = dir[0] = fname[0] = ext[0] = '\0';
  28.     
  29.     for (i = 0; (c=path[i]) != '\0'; i++) {
  30.         if (iskanji(c)) {
  31.             i++;    continue;
  32.         }
  33.         switch (c) {
  34.             case ':':
  35.                 colon    = i;    break;
  36.             case '\\':
  37.             case '/':
  38.                 yen        = i;    break;
  39.             case '.':
  40.                 if (0 < i && path[i-1] == '.')
  41.                     break;
  42.                 period    = i;    break;
  43.         }
  44.     }
  45.     tail = i-1;
  46.     
  47.     // ドライブ名
  48.     if (1 <= colon) {
  49.         colon = 1;
  50.         if (iskanji(path[1]))
  51.             colon = 0;
  52.     }
  53.     strncpy(drive, path, colon+1);
  54.     drive[colon+1] = '\0';
  55.     
  56.     // ディレクトリ名
  57.     if (colon + MAX_DIR <= yen) {
  58.         yen = colon+MAX_DIR-1;
  59.         if (iskanji(path[yen]))
  60.             yen--;
  61.     } else if (yen < colon)
  62.         yen = colon;
  63.     n = yen-colon;
  64.     strncpy(dir, &path[colon+1], n);
  65.     dir[n] = '\0';
  66.     
  67.     // ファイル名
  68.     fnend = period-1;
  69.     if (fnend < yen)
  70.         fnend = tail;
  71.     if (yen + MAX_FNAME <= fnend) {
  72.         fnend = yen+MAX_FNAME-1;
  73.         if (iskanji(path[fnend]))
  74.             fnend--;
  75.     }
  76.     n = fnend-yen;
  77.     strncpy(fname, &path[yen+1], n);
  78.     fname[n] = '\0';
  79.     
  80.     // 拡張子
  81.     if (period <= yen) {
  82.         ext[0] = '\0';
  83.         return;
  84.     }
  85.     if (fnend + MAX_EXT <= tail) {
  86.         tail = fnend+MAX_EXT-1;
  87.         if (iskanji(path[tail]))
  88.             tail--;
  89.     } else if (tail < period-1)
  90.         tail = fnend;
  91.     n = tail-fnend;
  92.     strncpy(ext, &path[fnend+1], n);
  93.     ext[n] = '\0';
  94.     return;
  95. }
  96.